const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const webpack = require("webpack");
const ESLintPlugin = require('eslint-webpack-plugin');

module.exports = {
  entry: {
    main: "./src/main.js",
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: "babel-loader",
        options: {
          presets: ['@babel/preset-env']
        }
      },
      {
        test: /\.(jpg|png|gif)$/,
        use: {
          loader: "url-loader",
          options: {
            name: "[name]_[hash].[ext]",
            outputPath: "img/",
            limit: 5000,
            esModule: false,
          },
        },
      },
      {
        test: /\.(eot|ttf|svg)$/,
        use: {
          loader: "file-loader",
        },
      },
    ],
  },
  plugins: [
    new webpack.DefinePlugin({
      BASE_URL: '"/"',
    }),
    new VueLoaderPlugin(),
    new ESLintPlugin({
      // 使用 path.join(__dirname, 'src') 报错
      files: 'src',
      extensions: ['js', 'vue']
    }),
    new HtmlWebpackPlugin({
      template: "./public/index.html",
      title: "webpack-vue-app",
    }),
  ]
};
